/*
Author : 
	aziza yasser: 15898607
	sayli hidir: 06061308
*/

#include "Deque.h"

Deque::Deque(): start(PSEUDO), end(PSEUDO), anz(0){
}


Deque::Deque(const Deque& ref){
	start = ref.start;
	anz = ref.anz;
//	copyAll(ref);
}


Deque::~Deque(){
//	eraseAll();
}
		
void Deque::PushFront(POSITION q){
	q->SetSuc(start);
	start = q;
	anz ++;
}

void Deque::PopFront(void){
	if(anz == 0)
		return;
	POSITION second = start->GetSuc();
	start = second;
	anz --;
}


void Deque::PushBack(POSITION q){
	if(anz == 0){
		start =q;
	}
	POSITION tmp = start;

	for(int i= 1; i < anz; i++){
		tmp = tmp->GetSuc();
	}

	tmp->SetSuc(q);
	q->SetSuc(PSEUDO);
	end = q;
	anz++;
}


void Deque::PopBack(void){
	if(anz == 0)
		return;
	POSITION tmp = start;
	for(int i= 2; i < anz; i++)
		tmp = tmp->GetSuc();

	tmp->SetSuc(PSEUDO);
	anz--;

}

void Deque::display(){
	POSITION tmp;
    	tmp = start;
	for(int i= 0; i < anz; i++){
		tmp->display();
		tmp = tmp->GetSuc();
	}

	cout << "||"<< anz << endl; 
}

void Deque::eraseAll(){
	POSITION tmp;
	while(start->GetSuc() != PSEUDO){
		tmp = start;
		start = start->GetSuc();
		delete tmp;
	}

}

void Deque::copyAll(const Deque &ref){
	POSITION tmp = ref.start;
	start = tmp;
	while(tmp->GetSuc() != PSEUDO){
		tmp = tmp->GetSuc();
		start->SetSuc(tmp->copy());
	}

}

